package com.cloud.adrian.novel.resource.controller;

import com.cloud.adrian.novel.common.constant.ApiRouterConstants;
import com.cloud.adrian.novel.common.resp.RestResp;
import com.cloud.adrian.novel.resource.dto.resp.ImgVerifyCodeResp;
import com.cloud.adrian.novel.resource.service.ResourceService;
import com.cloud.adrian.novel.user.dto.resp.UserRegisterRespDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 资源前台门户-验证码、图片 api控制器
 * @Author: xiangguiliang
 * @version: 1.0
 * @since: 2024/05/24
 */
@Tag(name = "ResourceController", description = "资源前台门户-验证码、图片 api")
@RestController
@RequestMapping(ApiRouterConstants.API_FRONT_RESOURCE_URL_PREFIX)
@RequiredArgsConstructor
public class ResourceController {
    private final ResourceService resourceService;

    @Operation(summary = "获取验证码")
    @GetMapping("img_verify_code")
    public RestResp<ImgVerifyCodeResp> getImgVerifyCode() throws IOException {
        return resourceService.getImgVerifyCode();
    }

    @Operation(summary = "图片上传接口")
    @PostMapping("/image")
    public RestResp<String> uploadImage(
            @Parameter(description = "图片文件") @RequestParam("file") MultipartFile file) throws IOException {
        return resourceService.uploadImage(file);
    }
}
